﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace Solitaire {
    class Deck {
        private List<Card> deck;

        public Deck() {
            deck = new List<Card>();
            for (int s = 0; s < 4; s++) {
                for (int r = 1; r <= 13; r++) {
                    deck.Add(new Card((CardSuit)s, (CardRank)r));
                }
            }
            shuffle();
        }

        public void shuffle() {
            Random rand = new Random();
            int index;
            Card tmpCard;
            for (int i = 0; i < (deck.Count * 5); i++) {
                index = rand.Next(deck.Count);
                tmpCard = deck.ElementAt<Card>(index);
                deck.RemoveAt(index);
                deck.Add(tmpCard);
            }
        }

        public void LoadContent(ContentManager content) {
            foreach (Card card in deck) {
                card.LoadContent(content);
            }
        }

        public Card drawCard() {
            Card toRet = null;
            if (deck.Count > 0) {
                toRet = deck.ElementAt<Card>(0);
                deck.RemoveAt(0);
            }
            return toRet;
        }

    }
}
